package jw3.c10.controllner;

import jw3.c10.model.Station;
import jw3.c10.utils.DBConnection;
import jw3.c10.utils.QueryByClass;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.List;

public class StationController {
    public static List<Station> getAll(int RID){
        String sql="select Station from station where RID=?";
        QueryByClass<Station> qc=new QueryByClass<Station>();
        return qc.select(Station.class,sql,RID);
    }
    public static int getSID(String Station){
        String sql="select SID from station where station=?";
        QueryByClass<Station> qc=new QueryByClass<Station>();
        return qc.select(Station.class,sql,Station).get(0).getSID();
    }
    public static  boolean zj(int r, String s){
        boolean  a=false,b=false;

//        String sql="insert Role values(0,?)";
        String sql1="insert Station values(0,?,?)";

        try {
            Connection conn= DBConnection.getConnection();
//            PreparedStatement ps=conn.prepareStatement(sql);
            PreparedStatement ps=conn.prepareStatement(sql1);
//          ps.setInt(1,r.getRID());
//            ps.setString(1,r.getRName());
//
//            if (ps.executeUpdate()>0) a=true;
//            ps1.setInt(1,s.getRID());
            ps.setInt(1,r);
            ps.setString(2, s);

            if (ps.executeUpdate()>0) b=true;
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    public static boolean logOut(int id){
        String sql="delete from Role where RID like ?";
        return DBConnection.zsg(sql,id);
    }
    public static String getStation(int SID){
        String sql="select b.Station from scenicspot a join station b on a.SID=b.SID where a.SID=? limit 1";
        QueryByClass<Station> qc=new QueryByClass<Station>();
        return qc.select(Station.class,sql,SID).get(0).getStation();
    }
}
